﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace GTA.Common
{
    public class Util
    {
        public static String GetFullException(Exception ex)
        {
            StringBuilder message = new StringBuilder(ex != null ? ex.ToString() : String.Empty);
            if (ex != null && ex.InnerException != null)
                message.Append(GetFullException(ex.InnerException));
            return message.ToString();
        }
        public static object Deserialize(String path, Type type)
        {
            object value = null;
            if (File.Exists(path))
            {
                XmlSerializer deserializer = new XmlSerializer(type);
                FileStream stream = new FileStream(path, FileMode.Open);
                value = deserializer.Deserialize(stream);
                stream.Close();
            }
            return value;
        }
        public static void Serialize(String path, Type type, object value)
        {
            XmlSerializer serializer = new XmlSerializer(type);
            FileStream stream = new FileStream(path, FileMode.Create);
            serializer.Serialize(stream, value);
            stream.Close();
        }
    }
}